import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;

import 'package:school_safe_teacher/resourse/app_colors.dart';

import 'action.dart';
import 'state.dart';

Reducer<ChangePwdState> buildReducer() {
  return asReducer(
    <Object, Reducer<ChangePwdState>>{
      ChangePwdAction.action: _onAction,
      ChangePwdAction.showPwd: _onChangeShowPwd,
    },
  );
}

ChangePwdState _onAction(ChangePwdState state, Action action) {
  final ChangePwdState newState = state.clone();
  if (newState.mobile.length == 11 &&
      newState.code.length > 0 &&
      newState.pwd.isNotEmpty) {
    newState
      ..loginTextColor = Colors.white
      ..loginBtnStartColor = AppColors.loginLeft
      ..loginBtnEndColor = AppColors.loginRight;
  } else {
    newState
      ..loginTextColor = AppColors.cantClickTextColor
      ..loginBtnStartColor = AppColors.loginBtnColor
      ..loginBtnEndColor = AppColors.loginBtnColor;
  }
  return newState;
}

ChangePwdState _onChangeShowPwd(ChangePwdState state, Action action) {
  final ChangePwdState newState = state.clone();
  if (!newState.showPwd) {
    newState..pwdCanSeeImg = "images/pwd_can_see@2x.png";
  } else {
    newState..pwdCanSeeImg = "images/pwd_cannot_see@2x.png";
  }
  return newState;
}
